<?php
namespace app\index\controller;

use app\common\model\SeedingFirst as SeedingFirstModel;

use app\common\component\seed\SeedService;
use app\common\component\fruit\FruitService;

class Index extends ControllerBase {
	public function _initialize() {
		$this -> checkLogin();
	}

    public function index() {
    	$userId = \think\Session::get('user_id');

		// 获取每天收益
		$seedingFirstServiceGetProfit = (new \app\common\component\seeding\SeedingFirstService()) -> getProfit($userId);
		$this -> view -> assign('seedGrowUpTotal', $seedingFirstServiceGetProfit['data']['total']);

		$currentTime = time();

		$fruitServiceFind = (new FruitService()) -> find($userId);
		if(isset($fruitServiceFind['data']['fruit']['fruit_first'])) {
			$this -> view -> assign('fruitFirst', $fruitServiceFind['data']['fruit']['fruit_first']);
		} else {
			$this -> view -> assign('fruitFirst', 0);
		}

		$seedServiceFind = (new SeedService()) -> find($userId);
		if(isset($seedServiceFind['data']['seed']['seed_first'])) {
			$this -> view -> assign('seedFirst', $seedServiceFind['data']['seed']['seed_first']);
		} else {
			$this -> view -> assign('seedFirst', 0);
		}

		$selectSeeding = SeedingFirstModel::where('user_id = ' . $userId . ' AND status in(3, 4)') -> select();
		$seedings = [];
		foreach($selectSeeding as $seeding) {
			$seedings[$seeding['sort']] = $seeding;
		}

		$this -> view -> assign('seedings', $seedings);

        return $this -> view -> fetch();
    }
}
?>